package com.qiantu.phone.ui.dialog;

import android.content.Context;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.qiantu.phone.R;
import com.qiantu.phone.ui.adapter.AddDeviceMethodAdapter;
import com.lxj.xpopup.core.BottomPopupView;

public class BottomConfigNetworkDialog extends BottomPopupView {

    private RecyclerView mRecyclerView;
    private AddDeviceMethodAdapter mAdapter;

    public BottomConfigNetworkDialog(@NonNull Context context) {
        super(context);
    }

    @Override
    protected int getImplLayoutId() {
        return R.layout.dialog_config_network;
    }

    // 执行初始化操作，比如：findView，设置点击，或者任何你弹窗内的业务逻辑
    @Override
    protected void onCreate() {
        super.onCreate();
        mRecyclerView = findViewById(R.id.recycler_view);
        if(mAdapter == null){
            return;
        }
        GridLayoutManager gridLayoutManager = new GridLayoutManager(getContext(), mAdapter.getItemCount());
        mRecyclerView.setLayoutManager(gridLayoutManager);
        mRecyclerView.setAdapter(mAdapter);
    }

    public void setAdapter(AddDeviceMethodAdapter adapter){
        mAdapter = adapter;
        if(mRecyclerView != null){
            GridLayoutManager gridLayoutManager = new GridLayoutManager(getContext(), mAdapter.getItemCount());
            mRecyclerView.setLayoutManager(gridLayoutManager);
            mRecyclerView.setAdapter(adapter);
        }
    }

    public AddDeviceMethodAdapter getAdapter() {
        return mAdapter;
    }

    // 设置最大宽度，看需要而定
    @Override
    protected int getMaxWidth() {
        return super.getMaxWidth();
    }

    // 设置最大高度，看需要而定
    @Override
    protected int getMaxHeight() {
        return super.getMaxHeight();
    }

    /**
     * 弹窗的宽度，用来动态设定当前弹窗的宽度，受getMaxWidth()限制
     *
     * @return
     */
    protected int getPopupWidth() {
        return 0;
    }

    /**
     * 弹窗的高度，用来动态设定当前弹窗的高度，受getMaxHeight()限制
     *
     * @return
     */
    protected int getPopupHeight() {
        return 0;
    }
}
